package ops.view.tables;

import java.util.LinkedHashSet;
import java.util.LinkedList;

import javax.swing.table.DefaultTableModel;

public class CustomTableModel extends DefaultTableModel {
	
	private LinkedList<Class<?>> columnsClass = new LinkedList<Class<?>>();
	private LinkedList<Integer> editableColumns = new LinkedList<Integer>();
	
	protected CustomTableModel(LinkedHashSet<Column> columns) {
		super();
		
		int i = 0;
		for (Column column : columns) {
			columnsClass.add(column.getClazz());
			
			if (column.isEditable())
				editableColumns.add(i);
			
			i++;
			
			addColumn(column.getColumnName());
		}
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		return editableColumns.contains(column);
	}
	
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return columnsClass.get(columnIndex);
	}

}